package com.ah._08cluster;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.Arrays;
import java.util.List;

/**
 * 生产者
 */
public class Produce {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        //创建生产者对象
        DefaultMQProducer dmp = new DefaultMQProducer("cluster_produce_group");
        //设置命名空间地址
        dmp.setNamesrvAddr("192.168.19.132:9876");
        //启动生产者
        dmp.start();

        //创建标签
        for (int i = 1; i <= 10; i++) {
            Message message = new Message("cluster_topic", "","keys"+i, ("消息" + i).getBytes());
            //发送消息
            SendResult result = dmp.send(message);
            System.out.println("result = " + result);
        }





        //关闭生产者impletopic
        dmp.shutdown();
    }
}
